<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;

class AdminController extends CommonController {
    /*账号管理*/
    public function index(){
        $page = A('Admin/Page');
        $table  = 'user';
        $field  = '*';
        $where  = "deletes = 1";
        $order  = 'id';
        $sum    = 20;
        $join   = 0;
        $info   = $page ->page($table, $field, $where, $order, $sum, $join);
        $this->assign('list',$info[0]);// 赋值数据集
        $this->assign('page',$info[1]);// 赋值分页输出
        $this->display();
    }
/*加载账号修改页面*/
    public function update(){
        $user = M('user');
        $uid = I('get.uid');
        $data = $user -> where("deletes = 1 and id = $uid")-> find();
        $this->assign('data',$data);
        $this->display();
    }
/*执行修改条件*/
    public function update_edit(){
        $user = M('user');
        if(!empty($_POST['name'])) {
            $id = $_POST['id'];
            $data['name'] = $_POST['name'];
            $data['sex'] = $_POST['sex'];
            $data['birthday'] = strtotime($_POST['birthday']);
            $data['introduction'] = $_POST['introduction'];
            $data['company'] = $_POST['company'];
            $data['department'] = $_POST['department'];
            $data['position'] = $_POST['position'];
            $data['email'] = $_POST['email'];
            $data['phone'] = $_POST['phone'];
            $data['mobilephone'] = $_POST['mobilephone'];
            $data['address'] = $_POST['address'];
            $data['web'] = $_POST['web'];
            if ($_POST['password'] != '' && $_POST['repass'] != '') {
                $data['password'] = md5('wcnmlgb' . md5($_POST['password']));
                $data['repass'] = md5('wcnmlgb' . md5($_POST['repass']));
            }
            $data['createtime'] = time();
            $result = $user ->where("deletes = 1 and id = $id ")->save($data);
            if($result){
                echo "<script>alert('修改信息成功');location.href='".U('Admin/index')."';</script>";
                exit;
            }else{
                echo "<script>alert('修改信息失败');location.href='".U('Admin/index')."';</script>";
                exit;
            }
        }else{
            echo "<script>alert('用户名不能为空，修改信息失败');location.href='".U('Admin/index')."';</script>";
            exit;
        }

    }
    /*删除*/
    public function delete(){
        $id = I('post.id');
        $user=M('user');
        $data['deletes'] = 2;
        $rs = $user->where("id = $id")->save($data);
        if($rs){
            $this->ajaxReturn("ok");
        } else {
            $this->ajaxReturn("sss");
        }
    }
}